import { defHttp } from '/@/utils/http/axios';
import { GetUserListResponseModel, UserModel } from './model/userModel';
import { GetAllRoleListResponseModel } from './model/roleModel';
// 定义请求地址的枚举
enum Api {
  GetUserList = '/admin/acl/user',
  RemoveUser = '/admin/acl/user/remove',
  SaveUser = '/admin/acl/user/save',
  UpdateUser = '/admin/acl/user/update',
  GetUserRoleList = '/admin/acl/user/toAssign',
  AssignUserRoleList = '/admin/acl/user/doAssign',
}

export const getUserListApi = (page: number, limit: number) => {
  return defHttp.get<GetUserListResponseModel>({
    url: Api.GetUserList,
    params: `/${page}/${limit}`,
  });
};

export const saveUserApi = (user: UserModel) => {
  return defHttp.post<null>({
    url: Api.SaveUser,
    data: user,
  });
};

export const getUserRoleListApi = (userId: string) => {
  return defHttp.get<GetAllRoleListResponseModel>({
    url: Api.GetUserRoleList,
    params: `/${userId}`,
  });
};

export const assignUserRoleListApi = (userId: string, roleId: string[]) => {
  return defHttp.post<GetAllRoleListResponseModel>({
    url: Api.AssignUserRoleList,
    params: `?userId=${userId}&roleId=${roleId}`,
  });
};
